package cn.stylefeng.guns.modular.fruits.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.fruits.entity.FruitsOrderOut;
import cn.stylefeng.guns.modular.fruits.mapper.FruitsOrderOutMapper;
import cn.stylefeng.guns.modular.fruits.model.params.FruitsOrderOutParam;
import cn.stylefeng.guns.modular.fruits.model.result.FruitsOrderOutResult;
import  cn.stylefeng.guns.modular.fruits.service.FruitsOrderOutService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 出库单管理 服务实现类
 */
@Service
public class FruitsOrderOutServiceImpl extends ServiceImpl<FruitsOrderOutMapper, FruitsOrderOut> implements FruitsOrderOutService {

    @Override
    public void add(FruitsOrderOutParam param){
        FruitsOrderOut entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FruitsOrderOutParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(FruitsOrderOutParam param){
        FruitsOrderOut oldEntity = getOldEntity(param);
        FruitsOrderOut newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FruitsOrderOutResult findBySpec(FruitsOrderOutParam param){
        return null;
    }

    @Override
    public List<FruitsOrderOutResult> findListBySpec(FruitsOrderOutParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(FruitsOrderOutParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findzhifacangOutPagelist(FruitsOrderOutParam param,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findzhifacangOutPagelist(pageContext, param, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(FruitsOrderOutParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private FruitsOrderOut getOldEntity(FruitsOrderOutParam param) {
        return this.getById(getKey(param));
    }

    private FruitsOrderOut getEntity(FruitsOrderOutParam param) {
        FruitsOrderOut entity = new FruitsOrderOut();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public int countBydate(FruitsOrderOutParam to,Long operateId) {
		Integer a;
		a = this.baseMapper.countBydate(to, operateId);
		if (a == null) {
			return 0;
		}
		return a;
	}

}
